Skip to content

chore(github-copilot): restore stream chunk type safety#33636

Open
Robin1987China wants to merge 1 commit into
anomalyco:devfrom
Robin1987China:fix-stream-type-safety
Open

chore(github-copilot): restore stream chunk type safety#33636
Robin1987China wants to merge 1 commit into
anomalyco:devfrom
Robin1987China:fix-stream-type-safety

Conversation

@Robin1987China

@Robin1987China Robin1987China commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #33093

Type of change

  • Bug fix

What does this PR do?

Restores TypeScript type safety on the chunk stream transform callback in OpenAICompatibleChatLanguageModel.doStream().

ProviderErrorStructure<any> passes ZodType<any> as the error schema to the generic createOpenAICompatibleChatChunkSchema. The generic infers any, so z.union([successSchema, ZodType<any>]) collapses output to any. This propagates through z.infer<typeof chunkSchema> to the TransformStream's ParseResult<any>, leaving all chunk.value accesses (choices, usage, delta, etc.) untyped.

Fix: extract the success chunk schema into a named const, derive a concrete type, and use a non-generic version of the chunk schema builder with an explicit cast. This preserves runtime validation (error schema still participates in the union) while giving TypeScript a proper type for narrowing.

How did you verify your code works?

  • bun typecheck — zero new errors
  • bun test --filter copilot-chat-model — 11/11 pass
  • Runtime behavior unchanged: error schema still validates error chunks in the union

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Replace the generic createOpenAICompatibleChatChunkSchema with a
non-generic version that preserves the output type. The  from
ProviderErrorStructure<any> was propagating through the union schema
to the TransformStream, leaving all chunk.value accesses untyped.
Extract the success schema into a named constant and cast the union
return to a concrete type so the transform callback regains type
checking on choices, usage, delta, etc.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Jun 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type safety loss in Copilot chat chunks and inline process.env writes in provider

1 participant